const actions = {
  // 获取数据
  setData({
    commit
  }) {
    let phoneData = JSON.parse(localStorage.getItem('phoneData') || '[]')
    // const totalPrice = Number(localStorage.getItem('totalPrice') || '0')
    // const totalNum = Number(localStorage.getItem('totalMount') || '0')
    const cartList = JSON.parse(localStorage.getItem('cartList') || '[]')

    phoneData = phoneData.map((item) => {
      const picsData = JSON.parse(item.pics)
      item.img = picsData[0][0][0]
      return item
    })
    commit('SET_DATA', {
      phoneData,
      cartList
    })
  },
  // 更新购物车数量
  setCart({
    commit
  }, {
    isAdd,
    good
  }) {
    if (isAdd) {
      // 增加购物车数量
      commit('ADD_CART', good)
    } else {
      // 减少购物车数量
      commit('SUB_CART', good)
    }
  }
}
export default actions
